package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.bean.BeanGoodChangjing;
import nero.yncc.com.createart.bean.GodBean;
import nero.yncc.com.createart.custom.MyRecyclerView;
import nero.yncc.com.createart.interfaces.InterfaceDoSomeThing;
import nero.yncc.com.createart.utils.MyLayoutManager;

/**
 * Created by nero on 17-6-27.
 */

public class AdapterGuigeIn extends BaseAdapter {

    Context context;
    ArrayList<GodBean.SpecAttr> arrayList;
    HashMap<String, BeanGoodChangjing> hashMap;

    public AdapterGuigeIn(Context context, ArrayList<GodBean.SpecAttr> arrayList, HashMap<String, BeanGoodChangjing> hashMap) {
        this.context = context;
        this.arrayList = arrayList;
        this.hashMap=hashMap;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holer;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.adapter_detail_in, null);
            holer = new Holder(view);
            view.setTag(holer);
        } else {
            holer = (Holder) view.getTag();
        }

        GodBean.SpecAttr bean = arrayList.get(i);
        holer.tv_content.setText(bean.getName());
        MyLayoutManager layout = new MyLayoutManager(context);
        //必须，防止recyclerview高度为wrap时测量item高度0
        layout.setAutoMeasureEnabled(true);
        holer.rc_list.setLayoutManager(layout);
        if(bean.getList()!=null){
            AdapterDetailInandIn adapterDetailInandIn = new AdapterDetailInandIn(context, bean.getList(),new InterfaceDoSomeThing());
            holer.rc_list.setAdapter(adapterDetailInandIn);
            adapterDetailInandIn.notifyDataSetChanged();
        }
        return view;
    }

    class Holder {
        TextView tv_content;
        MyRecyclerView rc_list;

        public Holder(View itemView) {
            tv_content = itemView.findViewById(R.id.tv_content);
//            fl_inside=itemView.findViewById(R.id.fl_inside);
            rc_list = itemView.findViewById(R.id.rc_list);
        }
    }
}
